package com.lanqiao.gxnushop.service;

import com.lanqiao.gxnushop.entity.FinancialRecords;
import com.lanqiao.gxnushop.mapper.FinancialRecordsMapper;
import com.lanqiao.gxnushop.util.UUIdUtil;
import com.lanqiao.gxnushop.valueObject.Financial;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Schema(description = "财务记录服务")
@Service
public class FinancialRecordsService {
    @Autowired
    private FinancialRecordsMapper financialRecordsMapper;
    @Autowired
    private StoresService storesService;

    @Schema(description = "增加财务记录")
    public boolean add(FinancialRecords financialRecords)
    {
        if(storesService.select(financialRecords.getStoreId())!=null){
            financialRecords.setRecordId(UUIdUtil.getUserId());
            return financialRecordsMapper.add(financialRecords);
        }
        return false;
    }

    @Schema(description = "删除财务记录")
    public boolean delete(String recordId)
    {
        return financialRecordsMapper.delete(recordId);
    }

    @Schema(description = "根据店铺id删除所有财务记录")
    public boolean deleteByStoreId(String storeId)
    {
        return financialRecordsMapper.deleteByStoreId(storeId);
    }

    @Schema(description = "根据财务记录id查询财务记录")
    public FinancialRecords findById(String recordId)
    {
        return financialRecordsMapper.findById(recordId);
    }

    @Schema(description = "根据店铺id查询财务记录")
    public ArrayList<FinancialRecords> findByStoreId(String storeId)
    {
        return financialRecordsMapper.findByStoreId(storeId);
    }

    @Schema(description = "更新指定财务记录")
    public boolean update(FinancialRecords financialRecords)
    {
        return financialRecordsMapper.update(financialRecords);
    }

    /**店铺金额统计信息*/
    public ArrayList<Financial> list(Financial financial){
        ArrayList<Financial> list = financialRecordsMapper.list(financial);
        return list;
    }
}
